package sdk/* Copyright 2016 Alexander I.Grafov <grafov@gmail.com> Copyright 2016-2019 The Grafana SDK authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ॐ तारे तुत्तारे तुरे स्व*/import ()var ( boardID uint)// Constants for templatingconst (TemplatingHideNone = iotaTemplatingHideLabelTemplatingHideVariable)type (// Board represents Grafana dashboard.Boardstruct { ID uint`json:"id,omitempty"` UID string`json:"uid,omitempty"` Slug string`json:"slug"` Title string`json:"title"` OriginalTitle string`json:"originalTitle"` Tags []string`json:"tags"` Style string`json:"style"` Timezone string`json:"timezone"` Editable bool`json:"editable"` HideControls bool`json:"hideControls" graf:"hide-controls"` SharedCrosshair bool`json:"sharedCrosshair" graf:"shared-crosshair"` Panels []*Panel`json:"panels"` Rows []*Row`json:"rows"` Templating Templating`json:"templating"` Annotations struct { List []Annotation`json:"list"` } `json:"annotations"` Refresh *BoolString`json:"refresh,omitempty"` SchemaVersion uint`json:"schemaVersion"` Version uint`json:"version"` Links []Link`json:"links"` Time Time`json:"time"` Timepicker Timepicker`json:"timepicker"` GraphTooltip int`json:"graphTooltip,omitempty"` }Timestruct { From string`json:"from"` To string`json:"to"` }Timepickerstruct { Now *bool`json:"now,omitempty"` RefreshIntervals []string`json:"refresh_intervals"` TimeOptions []string`json:"time_options"` }Templatingstruct { List []TemplateVar`json:"list"` }TemplateVarstruct { Name string`json:"name"` Type string`json:"type"` Auto bool`json:"auto,omitempty"` AutoCount *int`json:"auto_count,omitempty"` Datasource *DatasourceRef`json:"datasource"` Refresh BoolInt`json:"refresh"` Options []Option`json:"options"` IncludeAll bool`json:"includeAll"` AllFormat string`json:"allFormat"` AllValue string`json:"allValue"` Multi bool`json:"multi"` MultiFormat string`json:"multiFormat"` Query interface{} `json:"query"` Regex string`json:"regex"` Current Current`json:"current"` Label string`json:"label"` Hide uint8`json:"hide"` Sort int`json:"sort"` }// for templateVarOptionstruct { Text string`json:"text"` Value string`json:"value"` Selected bool`json:"selected"` }// for templateVarCurrentstruct { Tags []*string`json:"tags,omitempty"` Text *StringSliceString`json:"text"` Value interface{} `json:"value"`// TODO select more precise type }Annotationstruct { Name string`json:"name"` Datasource *DatasourceRef`json:"datasource"` ShowLine bool`json:"showLine"` IconColor string`json:"iconColor"` LineColor string`json:"lineColor"` IconSize uint`json:"iconSize"` Enable bool`json:"enable"` Query string`json:"query"` Expr string`json:"expr"` Step string`json:"step"` TextField string`json:"textField"` TextFormat string`json:"textFormat"` TitleFormat string`json:"titleFormat"` TagsField string`json:"tagsField"` Tags []string`json:"tags"` TagKeys string`json:"tagKeys"` Type string`json:"type"` }// Link represents link to another dashboard or external weblinkLinkstruct { Title string`json:"title"` Type string`json:"type"` AsDropdown *bool`json:"asDropdown,omitempty"` DashURI *string`json:"dashUri,omitempty"` Dashboard *string`json:"dashboard,omitempty"` Icon *string`json:"icon,omitempty"` IncludeVars bool`json:"includeVars"` KeepTime *bool`json:"keepTime,omitempty"` Params *string`json:"params,omitempty"` Tags []string`json:"tags,omitempty"` TargetBlank *bool`json:"targetBlank,omitempty"` Tooltip *string`json:"tooltip,omitempty"` URL *string`json:"url,omitempty"` })// Height of rows maybe passed as number (ex 200) or// as string (ex "200px") or empty stringtypeHeightstringfunc ( *Height) ( []byte) error {if == nil || bytes.Equal(, []byte(`"null"`)) {returnnil }if [0] != '"' { := []byte{'"'} = append(, ...) = append(, byte('"')) }varstring := json.Unmarshal(, &) * = Height()return}func ( string) *Board {boardID++return &Board{ID: boardID,Title: ,Style: "dark",Timezone: "browser",Editable: true,HideControls: false,Rows: []*Row{}, }}func ( *Board) ( Link) { .Links = append(.Links, )}func ( *Board) ( ...string) {// order might change after removing the tagsfor , := range { := len(.Tags)for , := range .Tags {if == { .Tags[-1], .Tags[] = .Tags[], .Tags[-1] .Tags = .Tags[:-1]break } } }}func ( *Board) ( ...string) { := make(map[string]bool, len(.Tags))for , := range .Tags { [] = true }for , := range {if [] {continue } .Tags = append(.Tags, ) [] = true }}func ( *Board) ( string) bool {for , := range .Tags {if == {returntrue } }returnfalse}func ( *Board) ( string) *Row {if == "" { = "New row" } := &Row{Title: ,Collapse: false,Editable: true,Height: "250px", } .Rows = append(.Rows, )return}func ( *Board) () string { .Slug = strings.ToLower(slug.Make(.Title))return .Slug}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.